package com.lqfan.autoAnswerQ.controller.fileType;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lqfan.autoAnswerQ.controller.errorRecords.ErrorRecordsController;
import com.lqfan.autoAnswerQ.model.fileType.FileType;
import com.lqfan.autoAnswerQ.model.fileType.HandleFileType;
import com.lqfan.autoAnswerQ.model.quesBank.Question;
import com.lqfan.autoAnswerQ.service.fileType.IFileTypeService;
import com.lqfan.autoAnswerQ.utils.ResponseMessage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 *
 * @author zml
 * @since 2020-04-04
 */
@RestController
@RequestMapping(value = "/fileType",produces = MediaType.APPLICATION_JSON_VALUE)
@Api(value = "文件管理")
public class FileTypeController {
    private static final Logger logger = LoggerFactory.getLogger(FileTypeController.class);
    @Autowired
    IFileTypeService fileTypeService;

    @ApiOperation(value = "文件获取路径", notes = "文件获取路径")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", required = true, dataType = "String"),
            @ApiImplicitParam(name = "questionName", value = "题库类型", required = true, dataType = "String"),
            @ApiImplicitParam(name = "type", value = "文件类型", required = true, dataType = "int"),
    })
    @RequestMapping(value = "getPath", method = RequestMethod.POST)
    public ResponseMessage getPath(@RequestParam(value = "userId") String userId,
                                          @RequestParam(value = "questionName") String questionName,
                                          @RequestParam(value = "type") int type) {
        logger.info("文件获取路径");
        List<HandleFileType> paths = fileTypeService.getPath(userId,type,questionName);
        if(paths==null||paths.size()==0) {
            logger.info("文件获取路径失败");
            return ResponseMessage.fail("文件获取路径失败");
        }
        logger.info("文件获取路径成功");
        return ResponseMessage.success(paths);
    }

    @ApiOperation(value = "文件夹获取路径", notes = "文件夹获取路径")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", required = true, dataType = "String"),
            @ApiImplicitParam(name = "questionName", value = "题库类型", required = true, dataType = "String"),
            @ApiImplicitParam(name = "type", value = "文件类型", required = true, dataType = "int"),
    })
    @RequestMapping(value = "getFilePath", method = RequestMethod.POST)
    public ResponseMessage getFilePath(@RequestParam(value = "userId") String userId,
                                          @RequestParam(value = "questionName") String questionName,
                                          @RequestParam(value = "type") int type) {
        logger.info("文件夹获取路径");
        List<HandleFileType> paths = fileTypeService.getFilePath(userId,type,questionName);
        if(paths==null||paths.size()==0) {
            logger.info("文件夹获取路径失败");
            return ResponseMessage.fail("文件夹获取路径失败");
        }
        logger.info("文件夹获取路径成功");
        return ResponseMessage.success(paths);
    }
}

